package org.fly.service.impl;

import org.fly.bean.WxSetting;
import org.fly.bean.query.WxSettingQuery;
import org.fly.dao.WxSettingDao;
import org.fly.service.WxSettingService;
import org.fly.utils.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.fly.bean.common.BusinessException;
import java.util.List;

/**
* Created by autoCode on 2018-04-22 08:56:37.
*/
@Service
public class WxSettingServiceImpl implements WxSettingService {

    @Autowired
    WxSettingDao wxSettingDao;

    @Override
    public List<WxSetting> list(WxSettingQuery query) {
        return wxSettingDao.list(query);
    }

    @Override
    public long count(WxSettingQuery query) {
        return wxSettingDao.count(query);
    }

    @Override
    public WxSetting findById(String id) {
        return wxSettingDao.findById(id);
    }

    @Override
    public WxSetting find() {
        return wxSettingDao.find();
    }

    @Override
    public void save(WxSetting bean)  throws BusinessException {

    if(StringUtils.isNotBlank(bean.getId())){
         wxSettingDao.update(bean);
    }else {
        bean.setId(UUIDFactory.random());
        bean.setCreateTime(System.currentTimeMillis());
        wxSettingDao.insert(bean);
    }
    }

    @Override
    public void delete(String id) {
        wxSettingDao.delete(id);
    }
}
